package com.mark;

import com.mark.annotations.Source;

/**
 * @Description: 获取Java源文件路径工具类
 * @Author: Mark
 * @CreateDate: 2021/12/25 16:52
 * @Copyright : 豆浆油条个人非正式工作室
 */
public class SourceUtils {

    private SourceUtils() {
    }

    /**
     * 获取<code>@Source<code/>标志的Java的类的绝对路径
     *
     * @param sourceAnnotation 源文件
     * @return 路径
     */
    public static String getSourceAbsolutePath(Source sourceAnnotation) {
        if (sourceAnnotation == null) {
            return Constant.EMPTY_STR;
        }
        Class source = sourceAnnotation.source();
        String className = source.getName();

        StringBuilder builder = new StringBuilder(Constant.PROJECT_SRC_PATH);
        builder.append(className.replace(".", "\\"));
        builder.append(".java");
        return builder.toString();
    }
}
